//
// Created by jsjxsy on 2022/7/12.
//

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
void readContent(const char *fileName, const char *cmd) {
  FILE *file;
  file = fopen(fileName, "r");
  if (file) {
    char c = fgetc(file);
    while (c != EOF) {
      if (strcmp(cmd, "-p") == 0) {
        putchar(c);
      }
      if (strcmp(cmd, "-u") == 0) {
        putchar(toupper(c));
      }
      if (strcmp(cmd, "-l") == 0) {
        putchar(tolower(c));
      }
      c = fgetc(file);
    }
    fclose(file);
  } else {
    perror("file read error:");
  }
}

void readContent2(const char *fileName, const char *cmd) {
  FILE *file;
  file = fopen(fileName, "r");
  if (file) {
    while (!feof(file)) {
      char c = fgetc(file);
      if(c == EOF){
        break;
      }
      if (strcmp(cmd, "-p") == 0) {
        putchar(c);
      }
      if (strcmp(cmd, "-u") == 0) {
        putchar(toupper(c));
      }
      if (strcmp(cmd, "-l") == 0) {
        putchar(tolower(c));
      }
    }
    fclose(file);
  } else {
    perror("file read error:");
  }
}
int main(void) {
  readContent("test.txt", "-p");
  readContent("test.txt", "-u");
  readContent2("test.txt", "-l");
  return 0;
}